<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>postMessage demo</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="https://cdn.bootcdn.net/ajax/libs/ant-design-vue/2.0.0-rc.1/antd.min.css" rel="stylesheet">
        <style>
            #app{
              padding: 20px;
            }
        </style>
    </head>
    <body>
        <!--[if lt IE 7]>
            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->
        <div id="app">
            <h2>跨iframe通讯demo</h2>
            <h3>iframe A</h3>
            <a-form layout="inline" :model="form" @submit="send" @submit.native.prevent>
                <a-row>
                    <a-col>
                        <a-form-item label="普通消息">
                            <a-input v-model:value="form.message" placeholder="请输入给iframe B发送的消息"></a-input>
                        </a-form-item>
                        <a-form-item>
                            <a-button
                                type="primary"
                                html-type="submit"
                                :disabled="form.message === ''"
                            >
                                发送
                            </a-button>
                        </a-form-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col>
                        <a-form-item label="传送数据">
                            <a-radio-group v-model:value="form.data" button-style="solid">
                                <a-radio-button value="0">
                                    对象:{ name: 'foo', age: 11}
                                </a-radio-button>
                                <a-radio-button value="1">
                                    数组:[{ name: 'foo', age: 11}, { name: 'foo2', age: 12}]
                                </a-radio-button>
                            </a-radio-group>
                        </a-form-item>
                        <a-form-item>
                            <a-button
                                type="primary"
                                html-type="submit"
                            >
                                发送
                            </a-button>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
            <a-row>
                <a-col>来自iframe B的消息</a-col>
            </a-row>
            <a-textarea readonly type="textarea" v-model:value="messageFromOrther" :autosize="{minRows: 4, maxRows: 6}"></a-textarea>
            <iframe name="child" id="child" src="./child.html" frameborder="0" style="width: 100%;height: 330px;margin-top: 20px;border: 1px solid #191818;padding: 5px 10px"></iframe>
            <hr>
            <h2>窗口之间通讯</h2>
            <a-row :gutter="10">
                <a-col :span="3" >
                    <a-button @click='openNewWin("./newWin.html")' type="primary">打开新窗口</a-button>
                </a-col>
            </a-row>
            <a-form layout="inline" :model="form" :rules="rules" @submit="sendNewWinMessage" @submit.native.prevent>
                <a-row>
                    <a-col>
                        <a-form-item label="新窗口消息" name="newWinMessage">
                            <a-input v-model:value="form.newWinMessage" placeholder="请输入给新窗口消息发送的消息"></a-input>
                        </a-form-item>
                        <a-form-item>
                            <a-button
                                type="primary"
                                html-type="submit"
                                :disabled="form.newWinMessage === ''"
                            >
                                发送
                            </a-button>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </div>

        <script defer src="../js/postMessager.iife.js"></script>
        <script defer src="https://cdn.bootcdn.net/ajax/libs/vue/3.0.2/vue.global.prod.js"></script>
        <script defer src="https://cdn.bootcdn.net/ajax/libs/ant-design-vue/2.0.0-rc.1/antd.min.js"></script>
        <script defer src="../js/main.js"></script>
    </body>
</html>